package com.ydc.ln.tutorial.algorithm.work.zjh;

/**
 * 实现Integet.parseInt(String str);
 * 
 * @author ydc
 * @date 下午4:25:42 2013-6-26
 */
public class Ch01 {
    public static void main(String[] args) {
        int result = Ch01.myParseInt("12345");
        System.out.println(result);
    }

    public static int myParseInt(String str) {
        int result = 0;
        try {
            int length = str.length();
            int step = 1;
            for (int i = 0; i < length; i++) {
                char c = str.charAt(length - i - 1);
                result += step * (c * 1 - 48);
                step *= 10;
            }
        } catch (Exception e) {

        }

        return result;
    }
}
